<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>对象内多个对象数组和平</title>
    <style></style>
  </head>
  <body>
    <script>
      const listData = [
        {
          id: "0",
          date: "2024-05-30",
          time: "2024-5-30 10:00",
          text: "机场接机",
          planlalt: [105.459908, 29.022015],
        },
        {
          id: "1",
          date: "2024-05-30",
          time: "2024-5-30 11:00",
          text: "乾坤酒堡",
          planlalt: [105.561094, 28.889829],
        },
        {
          id: "2",
          date: "2024-05-30",
          time: "2024-05-30 12:00",
          text: "国宝窖池",
          planlalt: [105.4536, 28.884362],
        },
        {
          id: "3",
          date: "2024-05-30",
          time: "2024-05-30 13:00",
          text: "老窖总部",
          planlalt: [105.430842, 28.89027],
        },
        {
          id: "4",
          date: "2024-05-30",
          time: "2024-05-30 15:00",
          text: "佳乐金区",
          planlalt: [105.404098, 28.894536],
        },
        {
          id: "5",
          date: "2024-05-30",
          time: "2024-05-30 17:00",
          text: "山海休息",
          planlalt: [105.434975, 28.892242],
        },
        {
          id: "6",
          date: "2024-06-01",
          time: "2024-06-01 10:00",
          text: "山海出发",
          planlalt: [105.434975, 28.892242],
        },
        {
          id: "7",
          date: "2024-06-01",
          time: "2024-06-01 11:00",
          text: "老窖总部",
          planlalt: [105.430842, 28.89027],
        },
        {
          id: "8",
          date: "2024-06-01",
          time: "2024-06-01 12:00",
          text: "国宝窖池",
          planlalt: [105.4536, 28.884362],
        },
        {
          id: "9",
          date: "2024-06-01",
          time: "2024-06-01 13:00",
          text: "张坝景区",
          planlalt: [105.476726, 28.880506],
        },
        {
          id: "10",
          date: "2024-06-01",
          time: "2024-06-01 17:00",
          text: "万达广场",
          planlalt: [105.420509, 28.911875],
        },
        {
          id: "11",
          date: "2024-06-01",
          time: "2024-06-01 18:00",
          text: "机场送机",
          planlalt: [105.470434, 29.019763],
        },
      ];
      // 定义观察器的配置信息
      const obj = {
        dayone: [
          {
            id: 1,
            text: "机场接机",
            planTime: "10:00",
            plan: [105.459908, 29.022015],
          },
          {
            id: 2,
            text: "乾坤酒堡",
            planTime: "11:00",
            plan: [105.561094, 28.889829],
          },
          {
            id: 3,
            text: "国宝窖池",
            planTime: "12:00",
            plan: [105.4536, 28.884362],
          },
          {
            id: 4,
            text: "老窖总部",
            planTime: "13:00",
            plan: [105.430842, 28.89027],
          },
          {
            id: 5,
            text: "山海饭店休息",
            planTime: "17:00",
            plan: [105.434975, 28.892242],
          },
          {
            id: 1,
            text: "山海饭店出发",
            planTime: "10:00",
            plan: [105.434975, 28.892242],
          },
          {
            id: 2,
            text: "老窖总部",
            planTime: "11:00",
            plan: [105.430842, 28.89027],
          },
          {
            id: 3,
            text: "万达广场",
            planTime: "12:00",
            plan: [105.420509, 28.911875],
          },
          {
            id: 4,
            text: "机场送机",
            planTime: "17:00",
            plan: [105.470434, 29.019763],
          },
        ],
      };
      // 开始封装
      const mergeObjFun = (maplist) => {
        let arrlist = [];
        Object.keys(maplist).forEach((item) => {
          arrlist.push(...maplist[item]);
        });
        for (let i = 0; i < arrlist.length; i++) {
          arrlist[i].id = i + 1;
        }
        return arrlist;
      };
      const arr = mergeObjFun(obj);
      // console.log(arr);
      // 返回日期的指定天数，传入两个参数(日期,天数)
      const addDateCell = (date, days) => {
        const dateNew = new Date(date);
        // for(let i=0;i<num;i++){
        dateNew.setDate(dateNew.getDate() + days);
        const year = dateNew.getFullYear();
        const month = (dateNew.getMonth() + 1).toString().padStart(2, "0");
        const day = dateNew.getDate().toString().padStart(2, "0");
        return `${year}-${month}-${day}`;
      };
      //根据时间拆分数组
      const cellArrList = (dataList = [], daysnum = 1) => {
        const arrlist = [];
        let startdate = dataList[0].date;
        for (let i = 0; i < daysnum; i++) {
          // flagdate筛选条件
          let flagdate = addDateCell(startdate, i);
          const arr = dataList.filter((item) => item.date === flagdate);
          arrlist.push(arr);
        }
        return arrlist;
      };

      cellArrList(listData, 3);
      console.log(date);
    </script>
  </body>
</html>
